package com.itheima.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/*
 * 统一的响应结果
 * */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    //属性的设计:code,msg,data 属性必须与前端对应
    private Integer code;//1 成功 0失败
    private String msg;//
    private Object data;

    //设计两个静态方法,方便创建使用
    public static R ok() {
        R r = new R();
        r.setCode(1);
        return r;
    }

    public static R ok(Object data) {//查询操作,响应大量数据
        R r = new R();
        r.setCode(1);
        r.setData(data);
        return r;
    }

    public static R error(String msg) {//失败,返回数据
        R r = new R();
        r.setCode(0);
        r.setMsg(msg);
        return r;
    }
}
